package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要删除书的名字：");
        String name = scanner.nextLine();
        Book[] book = bookList.getBooks();
        int bookSize = bookList.getBookSize();
        //找到这本书
        int i = 0;
        for (; i < bookSize; i++) {
            if(book[i].getName().equals(name)) {
                break;
            }
        }
        if(i == bookSize) {
            System.out.println("该书不存在！");
        }
        //删除这本书
        for(;i < bookSize-1;i++) {
            book[i] = book[i+1];
        }
        book[i] = null;
    }
}
